import baseUrl from './baseUrl.js'


export const getSignUserInfo = () => {
	return new Promise((rev, rej) => {
		uni.request({
			url: baseUrl + '/user/getSignUserInfo',
			method: 'POST',
			data: {},
			success(res) {
				rev(res)
			},
			fail(err) {
				uni.showToast({
					title: '数据获取失败'
				})
				rej(err)
			}
		})
	})
}

export const getUserById = (id) => {
	return new Promise((rev, rej) => {
		uni.request({
			url: baseUrl + '/user/getUserById',
			method: 'POST',
			header:{
				'token': uni.getStorageSync('token'),
				'Content-type': 'application/x-www-form-urlencoded'
			},
			data: {
				id
			},
			success(res) {
				rev(res)
			},
			fail(err) {
				uni.showToast({
					title: '数据获取失败'
				})
				rej(err)
			}
		})
	})
}


export const loginUser = data => {
	return new Promise((rev, rej) => {
		uni.request({
			url: baseUrl + '/user/loginUser',
			method: 'POST',
			header: {
				'Content-type': 'application/x-www-form-urlencoded'
			},
			data,
			success(res) {
				rev(res)
			},
			fail(err) {
				uni.showToast({
					title: '数据获取失败'
				})
				rej(err)
			}
		})
	})
}

export const loginUser2 = () => {
	return new Promise((rev, rej) => {
		uni.request({
			url: baseUrl + '/user/loginUser',
			method: 'POST',
			header: {
				'token': uni.getStorageSync('token'),
				'Content-type': 'application/x-www-form-urlencoded',
				
			},
			data: {},
			success(res) {
				rev(res)
			},
			fail(err) {
				uni.showToast({
					title: '数据获取失败',
					icon:'error'
				})
				rej(err)
			}
		})
	})
}

export const signUser = data => {
	return new Promise((rev, rej) => {
		uni.request({
			url: baseUrl + '/user/signUser',
			method: 'POST',
			header: {
				'Content-type': 'application/x-www-form-urlencoded'
			},
			data,
			success(res) {
				rev(res)
			},
			fail(err) {
				uni.showToast({
					title: '数据获取失败',
					icon:'error'
				})
				rej(err)
			}
		})
	})
}


export const updOrGetUserInfo = data => {
	return new Promise((rev, rej) => {
		uni.request({
			url: baseUrl + '/user/updOrGetUserInfo',
			method: 'POST',
			header: {
				'token': uni.getStorageSync('token'),
				'Content-type': 'application/x-www-form-urlencoded'
			},
			data,
			success(res) {
				rev(res)
			},
			fail(err) {
				uni.showToast({
					title: '数据获取失败',
					icon:'error'
				})
				rej(err)
			}
		})
	})
}


export const getUserInfo = () => {
	return new Promise((rev, rej) => {
		uni.request({
			url: baseUrl + '/user/updOrGetUserInfo',
			method: 'POST',
			header: {
				'token': uni.getStorageSync('token'),
				'Content-type': 'application/x-www-form-urlencoded'
			},
			data: {
				type: 1
			},
			success(res) {
				rev(res)
			},
			fail(err) {
				uni.showToast({
					title: '数据获取失败',
					icon:'error'
				})
				rej(err)
			}
		})
	})
}




